﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace lcmyjobs.Web.Controls
{
    public partial class NewsList : System.Web.UI.UserControl
    {
        private int _count = 0;
        private int _typeid = 0;
        private string _linkname = "";
        private string _linkurl = "";
        private string _infourl = "";
        private string _para;
        private int _length = 0;

        /// <summary>
        /// 新闻字符显示的长度
        /// </summary>
        public int length
        {
            get { return _length; }
            set { _length = value; }
        }
        /// <summary>
        /// 参数，注意 参数是从第二个开始，请先加上前缀
        /// </summary>
        public string para
        {
            get { return _para; }
            set { _para = value; }
        }

        /// <summary>
        /// 超链接名（显示详细信息的页面，用于li内的链接地址）
        /// </summary>
        public string infourl
        {
            get { return _infourl; }
            set { _infourl = value; }
        }


        /// <summary>
        /// 超链接名
        /// </summary>
        public string linkname
        {
            get { return _linkname; }
            set { _linkname = value; }
        }
        /// <summary>
        ///  超链接地址（显示更多信息列表的页面，用于底部“更多”的链接地址）
        /// </summary>
        public string linkurl
        {
            get { return _linkurl; }
            set { _linkurl = value; }
        }
        
        /// <summary>
        /// 类型id
        /// </summary>
        public int typeid
        {
            get { return _typeid; }
            set { _typeid = value; }
        }
        /// <summary>
        /// 列表行数
        /// </summary>
        public int count
        {
            get { return _count; }
            set { _count = value; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind(length);
            }
        }

        private void Bind(int length)
        {
            DataSet ds_jyzd = new lcmyjobs.BLL.news().GetListNews(Convert.ToInt32(Application["webid"].ToString()), count, typeid);

            StringBuilder str = new StringBuilder("");

            if (ds_jyzd.Tables[0].Rows.Count > 0)
            {
                str.Append("<ul>");
                foreach (DataRow row in ds_jyzd.Tables[0].Rows)
                {
                    string content = GetStr(row["ntitle"].ToString(),length);
                    if (!string.IsNullOrEmpty(para))
                    {
                        //chg by liuhui 131007 伪静态
                        //str.Append("<li><a href='" + infourl + "-" + row["nid"] + para +"'>" + content + "</a></li>");
                        str.Append("<li><a target='_blank' href='" + infourl + "-" + row["nid"] + para + ".html'>" + content + "</a></li>");
                    }
                    else
                    {
                        str.Append("<li><a target='_blank' href='" + infourl + "-" + row["nid"] + ".html'>" + content + "</a></li>");
                    }
                   

                }
                str.Append("</ul>");
            }


            this.lti_newslist.Text = str.ToString();

            this.hy_link.Text = linkname;
            this.hy_link.NavigateUrl = linkurl;
        }

        private string GetStr(string str,int length)
        {
            string result = str;
            if (length == 0)
            {
                if (str.Length > 14)
                {
                    result = str.Substring(0, 14);
                }
            }
            else
            {
                if (str.Length > length)
                {
                    result = str.Substring(0, length);
                }
            }
            
            return result;
        }
    }
}